package cn.dnui_wwt524.dnuifood_16110100524.Adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;
import cn.dnui_wwt524.dnuifood_16110100524.R;
import cn.dnui_wwt524.dnuifood_16110100524.bean.FoodBean;


public class CommentsAdapter extends RecyclerViewAdapter<RecyclerView.ViewHolder> {
    public CommentsAdapter(Context context, List data, int layoutResource) {
        super(context, data, layoutResource);
    }
    @NonNull
    @Override
    public CommentsAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View v = layoutInflater.from(parent.getContext()).inflate(R.layout.foodinfo_item,parent,false);
        return new CommentsAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final FoodBean entity = (FoodBean) data.get(position);
        if (null == entity)
            return;
        CommentsAdapter.ViewHolder viewHolder = (CommentsAdapter.ViewHolder) holder;
        viewHolder.comments_name.setText(entity.getUsername());
        viewHolder.comments_date.setText(entity.getOrder_time());
        viewHolder.comments_intro.setText(entity.getContent());
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView comments_name,comments_date,comments_intro;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            comments_name=(TextView)itemView.findViewById(R.id.comments_name);
            comments_date=(TextView)itemView.findViewById(R.id.comments_date);
            comments_intro=(TextView) itemView.findViewById(R.id.comments_intro);
        }
    }
    @Override
    public int getItemCount() {
        return data.size();
    }
}
